// component/vide/video.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    data:{
      type: Object,
      // 数据类型
      value:{}
      // 数据值
      }
  },
  options: {
    styleIsolation: 'apply-shared'
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgUrl:getApp().globalData.imgUrl,
    swiperTyle: false,
    itemDTOList: []
  },
  attached: function () {
    let itemDTOList = this.properties.data.itemDTOList
    for (let val of itemDTOList) {
      val.PlayTyle = true
    }
   this.setData({
    itemDTOList: itemDTOList
   })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    goPlayVideo(event) { //开始播放视频
      var that = this;
      var item = event.currentTarget.dataset.item
      var videoplay = wx.createVideoContext('video' + item.id, this)
      wx.getNetworkType({ // 获取网络类型
        success: function (res) {
          if (res.networkType != 'wifi') {
            that.setData({
              showNotWifiPaly: true
            })
            setTimeout(function () {
              that.setData({
                showNotWifiPaly: false
              })
            }, 1500)
          }
        }
      })
      videoplay.play()
      let itemDTOList = this.data.itemDTOList
    for (let val of itemDTOList) {
      if(val.id == item.id) {
        val.PlayTyle = false
      }
    }
    this.setData({
      itemDTOList: itemDTOList
    })
      // that.setData({
      //   swiperTyle: false
      // })
    },
    palyEndLitten(event) { //监听播放完
      var item = event.currentTarget.dataset.item
      item.PlayTyle = false
      let itemDTOList = this.data.itemDTOList
      for (let val of itemDTOList) {
        if(val.id == item.id) {
          val.PlayTyle = true
        }
      }
      this.setData({
        itemDTOList: itemDTOList
      })
    },
  }
})
